package com.example.lianxi;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

public class CircleProgress extends View {
    private int mDefaultSize=500;   //默认大小
    private PointF mCirclePoint=new PointF();  //中心点
    private Paint mValuePaint;
    private float myValueSize;
    private float mValuePaintSet;   //y轴偏移量
    private Paint mArcPaint;   //弧度画笔
    private RectF mArcRect;  //矩形区域
    private float mSweepAngle;//开始扫过的弧度
    private float mDefaultAngle;//默认的弧度
    private float mArcWidth;   //弧度画笔的宽度
    private float   mStartAngle; //开始的弧度；
    private Paint mArcProgressPaint;  //进度画笔


    public CircleProgress(Context context) {
        super(context);
        initData();
        initPaint();
    }



    public CircleProgress(Context context, AttributeSet attrs) {
        super(context, attrs);
        initData();
        initPaint();
    }

    private void initData() {
        myValueSize=80;
        mDefaultSize=500;
        mDefaultAngle=300;
        mArcWidth=16;

    }

    private void initPaint() {
        mValuePaint=new Paint();
        mValuePaint.setColor(Color.parseColor("#333333"));
        mValuePaint.setTextSize(50);
        mValuePaint.setTextAlign(Paint.Align.CENTER);

        mArcPaint=new Paint();
        mArcPaint.setStrokeWidth(mArcWidth);
        mArcPaint.setStyle(Paint.Style.STROKE);
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mArcPaint.setColor(Color.parseColor("#777777"));

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(mDefaultSize,mDefaultSize);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawText(canvas);
        drawArc(canvas);
    }

    private void drawArc(Canvas canvas) {
         canvas.save();
         canvas.rotate(mStartAngle,mCirclePoint.x,mCirclePoint.y);
         canvas.restore();
    }

    private void drawText(Canvas canvas) {
        canvas.drawText("0",mCirclePoint.x,mValuePaintSet,mValuePaint);
    }

}
